package com.atguigu.gulimallcart.vo;

import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

public class CartVo {
    private List<CartItemVo> cartItemVoList;

    //商品数量
    private Integer productCount;

    //购物车商品类型数量
    private Integer countType;

    //减免
    private BigDecimal reduce=new BigDecimal(0);

    //总价
    private BigDecimal totalAmount;

    public List<CartItemVo> getCartItemVoList() {
        return cartItemVoList;
    }

    public void setCartItemVoList(List<CartItemVo> cartItemVoList) {
        this.cartItemVoList = cartItemVoList;
    }

    public Integer getProductCount() {
        Integer productNum=0;
        for(CartItemVo cart:cartItemVoList) {
            productNum+=cart.getCount();
        }
        productCount=productNum;
        return productCount;
    }

    public Integer getCountType() {
        Integer count=0;
        if(!CollectionUtils.isEmpty(cartItemVoList)){
            count=cartItemVoList.size();
        }
        productCount=count;
        return productCount;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal totalPrice=new BigDecimal(0);
        for(CartItemVo cart:cartItemVoList) {
            if(cart.getCheck()){
                totalPrice=totalPrice.add(cart.getTotalAmount());
            }
        }
        totalAmount=totalPrice.subtract(reduce);
        return totalAmount;
    }


}
